package com.zc.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: cong
 * @create: 2024/10/15
 */
@Configuration
public class GateWayConfig {
    /**
     * 配置了一个id为test_routh的路由规则，
     * 当访问地址 http://localhost:9527/baidu时会自动转发到地址：https://www.baidu.com/
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("test_route", r -> r.path("/discovery/**")
                        .uri("http://localhost:8081"))
                .build();
    }
}
